package com.jinhongone.pattern.behavior.interpret;


/**
 * @author jinho
 * @className Test
 * @description 测试类
 * @date 2025/4/21 10:40
 */
public class Test {

    public static void main(String[] args) {
        //定义数值标识
        Variable a = new Variable("a");
        Variable b = new Variable("b");
        Variable c = new Variable("c");
        Variable d = new Variable("d");
        //定义环境类，并将数值和数值标识关联
        Context context = new Context();
        context.assign(a, 1);
        context.assign(b, 2);
        context.assign(c, 3);
        context.assign(d, 4);
        //构建抽象语法树
        AbstractExpression expression = new Plus(new Minus(new Plus(a, b), new Plus(c, d)), new Plus(a, d));
        //解释表达式
        System.out.println(expression + " = " + expression.interpret(context));
    }
}
